package com.example.tvfoucssustom;

import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.example.tvfoucssustom.custom.TvTabLayout;

public class MainActivity extends AppCompatActivity {

    private TvTabLayout mTabLayout;
    private TvTabLayout mTabLayout1;
    private TvTabLayout mTabLayout2;
    private TvTabLayout mTabLayout3;
//    private TvTabLayout mTabLayout4;

    private TextView textView;
    private TextView textViewTwo;
    private TextView textViewThree;
    private TextView textViewFour;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mTabLayout = findViewById(R.id.tablayout);
        mTabLayout1 = findViewById(R.id.tablayout1);
        mTabLayout2 = findViewById(R.id.tablayout2);
        mTabLayout3 = findViewById(R.id.tablayout3);
//        mTabLayout4 = findViewById(R.id.tablayout4);

        textView = findViewById(R.id.tv_click);
        textViewTwo = findViewById(R.id.tv_clicktwo);
        textViewThree = findViewById(R.id.tv_clickthree);
        textViewFour = findViewById(R.id.tv_clickFour);
        ininView();
        mTabLayout2.addOnTabSelectedListener(new TvTabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TvTabLayout.Tab tab) {
//                Toast.makeText(MainActivity.this,"position "+tab.getPosition(),Toast.LENGTH_SHORT).show();
//                mTabLayout2.getTabStrip().setIndicatorDrawable(DrR.drawable.zx_p1_light);
                Log.e("kun", "onTabSelected " + tab.getPosition());
            }

            @Override
            public void onTabUnselected(TvTabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TvTabLayout.Tab tab) {

            }
        });
        mTabLayout2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    mTabLayout2.setIndicatorDrawable(ContextCompat.getDrawable(MainActivity.this, R.mipmap.zx_p1_light));
                } else {
                    mTabLayout2.setIndicatorDrawable(ContextCompat.getDrawable(MainActivity.this, R.color.transparent));
                }
            }
        });
//        mTabLayout4.setOnFocusChangeListener(new View.OnFocusChangeListener() {
//            @Override
//            public void onFocusChange(View v, boolean hasFocus) {
//                if (hasFocus) {
//                    mTabLayout4.setIndicatorDrawable(ContextCompat.getDrawable(MainActivity.this, R.mipmap.zx_p1_light));
//                } else {
//                    mTabLayout4.setIndicatorDrawable(ContextCompat.getDrawable(MainActivity.this, R.color.transparent));
//                }
//            }
//        });

        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, Homectivity.class));
            }
        });
        textViewTwo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, HomeCustomActivity.class));
            }
        });
        textViewThree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, HomecNoViewpagertivity.class));
            }
        });
        textViewFour.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, TabAndCustomActivity.class));
            }
        });
    }

    private void ininView() {
        // 代码动态添加tab
        for (int i = 0; i < 15; i++) {
            mTabLayout1.addTab(mTabLayout1.newTab().setText("标题" + i), i == 0);
            mTabLayout2.addTab(mTabLayout2.newTab().setText("标题" + i), i == 0);
            mTabLayout.addTab(mTabLayout.newTab().setText("标题" + i), i == 0);
            mTabLayout3.addTab(mTabLayout3.newTab().setText("标题" + i), i == 0);
//            mTabLayout4.addTab(mTabLayout4.newTab().setText("标题" + i), i == 0);


        }

    }

}
